﻿@{
    ViewBag.Title = "润滑明细";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section scripts{
    <script src="~/Areas/Dev/ViewModels/Dev.com.js"></script>
    <script src="~/Areas/Dev/ViewModels/Dev.viewModel.edit.js"></script>
    <script type="text/javascript">
            using(['numberbox','lookup','combobox']);
            var viewModel = function(){
                var self = this;
                Dev.viewModel.edit.apply(self,arguments);
                this.grid.size={w:6,h:151};
                this.grid.OnAfterCreateEditor = function(editors,row){

                };
                 this.grid.OnBeforeDestroyEditor = function (editors, row) {
                    //获取部门名称（显示值） 
                    row.Rhjlmx_Jcry = editors["Rhjlmx_Jcry"].target.lookup('textbox').val();
                    row.Rhjlmx_Fzry = editors["Rhjlmx_Fzry"].target.lookup('textbox').val();
                    row.Rhjlmx_Rhxm = editors["Rhjlmx_Rhxm"].target.lookup('textbox').val();
                };

                 this.saveClick = function () {
                    //保存主表及明细表
                    var bmmc=$("#Rhjl_Bmbh").combobox('getText');
                    self.form["Rhjl_Bmmc"]=bmmc;
                    var rymc=$("#Rhjl_Rhr").combobox('getText');
                    self.form["Rhjl_Rhr"]=rymc;
                    if (self.readonly()) return;
                    self.gridEdit.ended(); //结束grid编辑状态
                    var post = {           //传递到后台的数据
                        form: com.formChanges(self.form, data.form, self.setting.postFormKeys),
                        list: self.gridEdit.getChanges(self.setting.postListFields)
                    };
                    if ((self.gridEdit.ended() && com.formValidate()) && (post.form._changed || post.list._changed)) {
                        com.ajax({
                            url: self.urls.edit,
                            data: ko.toJSON(post),
                            success: function (d) {
                                com.message('success', self.resx.editSuccess);
                                ko.mapping.fromJS(post.form, {}, data.form); //更新旧值
                                self.gridEdit.accept();
                            }
                        });
                    }

                    };
                this.addRowClick = function(){
                        if (self.readonly()) return;
                        var sBillNo = this.scrollKeys.current();
                        //获取RowId 与单据编号
                        com.ajax({
                            type: 'GET',
                            url: this.urls.getrowid + 1,
                            data: { BillNo: sBillNo },
                            success: function (d) {
                                var row = $.extend({ Rhjlmx_BillNo: sBillNo, Rhjlmx_Flbh: d }, self.defaultRow);
                                self.gridEdit.addnew(row);
                            }
                        });

              };  
            };
            var data = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model));
            ko.bindingViewModel(new viewModel(data));
    </script>
    }
    <div class="z-toolbar">
        <a id="a_save" href="#" plain="true" class="easyui-linkbutton" icon="icon-save" data-bind="click:saveClick,linkbuttonDisable:readonly" title="保存">保存</a>
        <a id="a_undo" href="#" plain="true" class="easyui-linkbutton" icon="icon-undo" data-bind="click:rejectClick,linkbuttonDisable:readonly" title="撤消">撤消</a>
        <a id="a_audit" href="#" plain="true" class="easyui-linkbutton" icon="icon-user-accept" data-bind="click:auditClick,easyuiLinkbutton:approveButton" title="审核">审核</a>
        <a id="a_printer" href="#" plain="true" class="easyui-linkbutton" icon="icon-printer" title="打印" data-bind="click:printClick">打印</a>
        <div class="datagrid-btn-separator"></div>
        <a id="a_first" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_first" data-bind="click:firstClick,linkbuttonEnable:scrollKeys.firstEnable" title="第一条"></a> 
        <a id="a_previous" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_previous" data-bind="click:previousClick,linkbuttonEnable:scrollKeys.previousEnable" title="上一条"></a> 
        <a id="a_next" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_next" data-bind="click:nextClick,linkbuttonEnable:scrollKeys.nextEnable" title="下一条"></a> 
        <a id="a_last" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_last" data-bind="click:lastClick,linkbuttonEnable:scrollKeys.lastEnable" title="最后一条"></a> 
    </div>

    <div id="master" class="container_12" data-bind="inputwidth:0.9">
        <div class="grid_1 lbl">单据编号</div>
        <div class="grid_3 val"><input type="text" id="Rhjl_BillNo" name="Rhjl_BillNo"  data-bind="value:form.Rhjl_BillNo,readOnly:true" class="z-txt readonly"/></div>
        <div class="grid_1 lbl required">设备名称</div>
        <div class="grid_3 val"><input type="text"  data-bind="lookupValue:form.Rhjl_Sbbh,lookupReadOnly:readonly" required="true" class="z-txt easyui-lookup" data-options="lookupType:'sbda',multiple:false"/></div>
        <div class="grid_1 lbl required">润滑部门</div>
        <div class="grid_3 val"><input type="text" id="Rhjl_Bmbh" data-bind="lookupValue:form.Rhjl_Bmbh,lookupReadOnly:readonly" required="true" class="z-txt easyui-lookup" data-options="lookupType:'organize',multiple:false" /></div> 
        <div class="clear"></div> 
               

        <div class="grid_1 lbl required">润滑人</div>
        <div class="grid_3 val required"><input type="text" id="Rhjl_Rhr" data-bind="lookupValue:form.Rhjl_Rhr,lookupReadOnly:readonly"  required="true"  class="z-txt easyui-lookup" data-options="lookupType:'sysuser',multiple:false" /></div>
        <div class="grid_1 lbl">开始时间 </div>
        <div class="grid_3 val required"><input type="text" data-bind="dateboxValue:form.Rhjl_Kssj,dateboxReadOnly:readonly" required="true" class="z-txt easyui-datebox"  /></div>
        <div class="grid_1 lbl">结束时间</div>
        <div class="grid_3 val required"><input type="text" data-bind="dateboxValue:form.Rhjl_Jssj,dateboxReadOnly:readonly" required="true" class="z-txt easyui-datebox"  /></div>
        <div class="clear"></div>

        <div class="grid_1 lbl">润滑工时 </div>
        <div class="grid_3 val "><input type="text" data-bind="numberboxValue:form.Rhjl_Rhgs" required="true" class="z-txt easyui-numberbox "  /></div>
        <div class="grid_1 lbl">停机工时 </div>
        <div class="grid_3 val "><input type="text" data-bind="numberboxValue:form.Rhjl_Tjgs" required="true" class="z-txt easyui-numberbox" /></div>
        <div class="grid_1 lbl">润滑内容 </div>
        <div class="grid_3 val required "><input type="text" data-bind="value:form.Rhjl_Rhnr,readOnly:readonly" required="true" class="z-txt"  /></div>
        <div class="clear"></div>

        <div class="grid_1 lbl">具体要求 </div>
        <div class="grid_3 val required"><input type="text" data-bind="value:form.Rhjl_Rhyq,readOnly:readonly" required="true" class="z-txt"  /></div>
        <div class="grid_1 lbl">备注说明 </div>
        <div class="grid_3 val"><input type="text" data-bind="value:form.Rhjl_Remark,readOnly:readonly" class="z-txt"  /></div>

        <div class="clear"></div>
    </div>
  
    <div id="tt" class="easyui-tabs">  
        <div title="表单明细">
            <table id="list" data-bind="datagrid:grid">
                <thead>
                    <tr>
                        <th field="Rhjlmx_BillNo" hidden="true"></th>  
                        <th field="Rhjlmx_Flbh"   hidden="false"  >分录编号</th> 
                        <th field="Rhjlmx_Rhbw"   align="left"    width="150" editor="text" >润滑部位 </th> 
                        <th field="Rhjlmx_Rhxm"   align="left"    width="150" editor="{type:'lookup',options:{lookupType:'sbrhxm',parentField:'pid'}}" >润滑项目 </th> 
                         
                        <th field="Rhjlmx_Rhyq"   align="left"    width="150" editor="text" >润滑要求 </th>   
                        <th field="Rhjlmx_Wlmc"   align="left"    width="150" editor="text" >润滑油名称 </th>  
                        <th field="Rhjlmx_Ggxh"   align="left"    width="150" editor="text" >规格型号 </th>
                        
                          
                        <th field="Rhjlmx_Yl"     align="right"    width="60"  editor="{type:'numberbox',options:{precision:2}}" >用量 </th>  
                        <th field="Rhjlmx_Fzry"   align="left"    width="80"  editor="{type:'lookup',options:{lookupType:'sysuser',parentField:'pid'}}" >负责人员   </th>  
                        <th field="Rhjlmx_Jcry"   align="left"    width="80" editor="{type:'lookup',options:{lookupType:'sysuser',parentField:'pid'}}" >检查人员   </th>    
                        <th field="Rhjlmx_Remar"  align="left"    width="150" editor="text" >备注说明 </th> 
                          
                        <th field="CreatePerson"  sortable="true" align="center"  width="70"   >创建人</th>  
                        <th field="CreateDate"    sortable="true" align="center"  formatter="com.formatDate"    width="100" >创建日期</th>   
                    </tr>
                </thead>
            </table>  
            
            <div id="gridtb">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" data-bind="click:addRowClick,linkbuttonDisable:readonly">增加明细</a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" data-bind="click:removeRowClick,linkbuttonDisable:readonly">删除明细</a>
            </div>  
        </div>
        <div title="表单信息" class="hide" style="padding-top:2px;">
            <div class="container_12" id="BillDetail" data-bind="inputwidth:0.9,autoheight:181"> 
                <div class="clear"></div>
                <div class="grid_1 lbl">审批状态</div>
                <div class="grid_3 val"><input type="text" id="ApproveState" data-bind="value:form.ApproveState,readOnly:true" class="z-txt readonly"/></div>
                <div class="grid_1 lbl">审批意见</div>
                <div class="grid_3 val"><input type="text" id="ApproveRemark" data-bind="value:form.ApproveRemark,readOnly:true"  class="z-txt readonly"/></div>
                <div class="grid_1 lbl">审批人 </div>
                <div class="grid_3 val"><input type="text" id="ApprovePerson"data-bind="value:form.ApprovePerson,readOnly:true" class="z-txt readonly"/></div>

                <div class="clear"></div>
                <div class="grid_1 lbl">审批日期</div>
                <div class="grid_3 val"><input type="text" id="ApproveDate" data-bind="dateboxValue:form.ApproveDate,dateboxReadOnly:true"  class="z-txt easyui-datebox readonly"/></div>
                <div class="grid_1 lbl">编制日期</div>
                <div class="grid_3 val"><input type="text" id="CreateDate" data-bind="dateboxValue:form.CreateDate,dateboxReadOnly:true" class="z-txt easyui-datebox readonly" /></div>
                <div class="grid_1 lbl">编制人</div>
                <div class="grid_3 val "><input type="text" id="CreatePerson" data-bind="value:form.CreatePerson,readOnly:true" class="z-txt readonly" /></div>
                
                <div class="clear"></div>
                <div class="grid_1 lbl">修改日期</div>
                <div class="grid_3 val"><input type="text" id="UpdateDate" data-bind="dateboxValue:form.UpdateDate,dateboxReadOnly:true" class="z-txt easyui-datebox readonly" /></div>
                <div class="grid_1 lbl">修改人</div>
                <div class="grid_3 val "><input type="text" id="UpdatePerson" data-bind="value:form.UpdatePerson,readOnly:true" class="z-txt readonly" /></div>
            </div>
        </div> 
    </div>  